package sip

import (
	"encoding/xml"
	"fmt"

	"gitee.com/larry_wan/go-lib/etree"
)

type RecordInfo struct {
	DeviceID   string
	Name       string
	FilePath   string
	FileSize   string
	Address    string
	StartTime  string
	EndTime    string
	Secrecy    string //保密属性: 0-不涉密, 1-涉密
	Type       string //录像产生类型: time, alarm, manual, all
	RecorderID string //录像触发者ID
}

func (rec *RecordInfo) String() string {
	return fmt.Sprintf("RecordInfo{DeviceID=%s Name=%s FilePath=%s StartTime=%s EndTime=%s RecorderID=%s}", rec.DeviceID, rec.Name, rec.FilePath, rec.StartTime, rec.EndTime, rec.RecorderID)
}

func UnmarshalRecordInfo(e *etree.Element) (rec *RecordInfo, err error) {
	if e == nil {
		err = fmt.Errorf("xml not found")
		return
	}
	doc := etree.NewDocument()
	doc.SetRoot(e)
	doc.Indent(4)
	xmlStr, err := doc.WriteToString()
	if err != nil {
		return
	}
	_rec := &RecordInfo{}
	err = xml.Unmarshal([]byte(xmlStr), _rec)
	if err != nil {
		return
	}
	rec = _rec
	return
}
